package pathways;

/**
 * Title:        Pathways
 * Description:  Pure Java version of the Pathways Project.
 * Copyright:    Copyright (c) 2002
 * Company:      Ants Technologies
 * @author Veejay Sani
 * @version 1.0
 */
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import pathways.Database.Implementation.CDatabase;
import pathways.util.helper.CItemListModel;

public class CReactionDetailView extends JFrame
{
  private CReaction reaction;
  JPanel jPanel1 = new JPanel();
  JScrollPane scrollPaneSubs = new JScrollPane();
  JScrollPane scrollPaneProds = new JScrollPane();
  JList lstSubstrates = new JList();
  JList lstProducts = new JList();
  JLabel lblSubs = new JLabel();
  JLabel lblProds = new JLabel();
  JTextField txtEnzyme = new JTextField();
  JLabel lblEnzyme = new JLabel();
  JPanel jPanel2 = new JPanel();
  TitledBorder titledBorder1;
  JLabel lblecnumLabel = new JLabel();
  JLabel lblEcno = new JLabel();
  JLabel lblDescription = new JLabel();
  JTextArea txtDescription = new JTextArea();
  JButton cmdClose = new JButton();
  CItemListModel lstmdlSubs = null;
  CItemListModel lstmdlProds = null;
  JLabel lblSubs1 = new JLabel();
  
  public CReactionDetailView(CReaction rxn, CDatabase db)
  {
    this();
    
    rxn.read(rxn.getID(),db);
    
    reaction = rxn;
    loadReaction(rxn,db);
  }

  private void loadReaction(CReaction rxn, CDatabase db)
  {
    Vector subs = rxn.getAllSubstrates();
    Vector prods = rxn.getAllProducts();
    CEnzyme enzyme = rxn.getEnzyme();
    
    this.lstmdlSubs = new CItemListModel(subs);
    this.lstmdlProds = new CItemListModel(prods);
    
    this.lstSubstrates.setModel(this.lstmdlSubs);
    this.lstProducts.setModel(this.lstmdlProds);
    
    this.txtEnzyme.setText(enzyme.getName());
    this.lblEcno.setText(enzyme.getECNO2());
    this.txtDescription.setText(enzyme.getDescription(db));
  }
  
  private CReactionDetailView()
  {
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    
    pack();
    setSize(530,430);
  }
  private void jbInit() throws Exception
  {
    titledBorder1 = new TitledBorder("");
    jPanel1.setBorder(BorderFactory.createEtchedBorder());
    jPanel1.setBounds(new Rectangle(8, 7, 510, 181));
    jPanel1.setLayout(null);
    this.getContentPane().setLayout(null);
    scrollPaneSubs.setBounds(new Rectangle(14, 28, 176, 143));
    scrollPaneProds.setBounds(new Rectangle(320, 27, 176, 143));
    lblSubs.setHorizontalAlignment(SwingConstants.CENTER);
    lblSubs.setText("Substrates:");
    lblSubs.setBounds(new Rectangle(15, 6, 175, 18));
    lblProds.setBounds(new Rectangle(320, 6, 175, 18));
    lblProds.setHorizontalAlignment(SwingConstants.CENTER);
    lblProds.setText("Products:");
    txtEnzyme.setBounds(new Rectangle(194, 82, 119, 23));
    lblEnzyme.setHorizontalAlignment(SwingConstants.CENTER);
    lblEnzyme.setText("Enzyme:");
    lblEnzyme.setBounds(new Rectangle(194, 57, 120, 18));
    jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));
    jPanel2.setBounds(new Rectangle(8, 208, 510, 157));
    jPanel2.setLayout(null);
    lblecnumLabel.setText("ECNO:");
    lblecnumLabel.setBounds(new Rectangle(10, 15, 57, 17));
    lblEcno.setFont(new java.awt.Font("Dialog", 1, 12));
    lblEcno.setText("ECNO");
    lblEcno.setBounds(new Rectangle(122, 13, 313, 22));
    lblDescription.setText("Description:");
    lblDescription.setBounds(new Rectangle(10, 44, 84, 16));
    txtDescription.setBorder(BorderFactory.createLineBorder(Color.black));
    txtDescription.setText("Description goes herelllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll");
    txtDescription.setLineWrap(true);
    txtDescription.setBounds(new Rectangle(122, 44, 311, 104));
    cmdClose.setText("Close");
    cmdClose.setBounds(new Rectangle(181, 374, 143, 27));
    cmdClose.addActionListener(new java.awt.event.ActionListener()
    {
      public void actionPerformed(ActionEvent e)
      {
        cmdClose_actionPerformed(e);
      }
    });
    lblSubs1.setBounds(new Rectangle(15, 6, 175, 18));
    lblSubs1.setText("Substrates:");
    this.setResizable(false);
    this.getContentPane().add(jPanel1, null);
    jPanel1.add(scrollPaneSubs, null);
    scrollPaneSubs.getViewport().add(lstSubstrates, null);
    jPanel1.add(scrollPaneProds, null);
    scrollPaneProds.getViewport().add(lstProducts, null);
    jPanel1.add(lblSubs, null);
    jPanel1.add(lblProds, null);
    jPanel1.add(txtEnzyme, null);
    jPanel1.add(lblEnzyme, null);
    this.getContentPane().add(jPanel2, null);
    jPanel2.add(lblDescription, null);
    jPanel2.add(lblecnumLabel, null);
    jPanel2.add(lblEcno, null);
    jPanel2.add(txtDescription, null);
    this.getContentPane().add(cmdClose, null);
  }

  void cmdClose_actionPerformed(ActionEvent e)
  {
    this.dispose();
  }
}